import java.sql.*;
 
public class JDBCExample {
	
		
	public static void main(String[] argv) {
		
		
		System.out.println("-------- PostgreSQL "
				+ "JDBC Connection Testing ------------");
 
		try { // Initialisierung Treiber
 
			Class.forName("org.postgresql.Driver");
			
 
		} catch (ClassNotFoundException e) {
 
			System.out.println("Where is your PostgreSQL JDBC Driver? "
					+ "Include in your library path!");
			e.printStackTrace();
			return;
 
		}
 
		System.out.println("PostgreSQL JDBC Driver Registered!");
 
		Connection connection = null;
		
		
		try { // Verbindungsaufbau zu Datenbank
 
			connection = DriverManager.getConnection(
					"jdbc:postgresql://localhost:5432/CATDAT", "postgres",
					"dast");
			
			Statement statement = connection.createStatement();
			
			String query = "SELECT * FROM iket.event_earthquake";
			ResultSet result = statement.executeQuery(query);	
			
						
			
			
				while (result.next()) //interner Cursor wird auf die erste Zeile gesetzt
				{   
					
					Statement stmt = connection.createStatement();
					Float depth = result.getFloat(7);	
					
				
				if (depth <= 15) {
													
					
					String updateString = "UPDATE iket.event_earthquake SET depth=" + "'16,0' WHERE depth LIKE '16'";
					stmt.executeUpdate(updateString);	
					
					result.updateRow();
				}
				else{
											
					
					String update = "UPDATE iket.event_earthquake SET depth_0_bis_15km =" + "'1' WHERE depth_0_bis_15km LIKE '0'";
					stmt.executeUpdate(update);					
					
					} 
				
						
			
				} 
			
				result.close();	
				statement.close();
				connection.close();
				
				
		} catch (SQLException e) {
 
			System.out.println("Connection Failed! Check output console");
			e.printStackTrace();
			return;
			
			
		}
	
		
		if (connection != null) {
			System.out.println("You made it, take control your database now!");
			
			
		} 
		else {
			System.out.println("Failed to make connection!");
		}
	}
	

}